package com.teamcenter.rac.commands.changeownership;

import com.teamcenter.rac.aif.AbstractAIFOperation;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentGroup;
import com.teamcenter.rac.kernel.TCComponentGroupMember;
import com.teamcenter.rac.kernel.TCComponentTask;
import com.teamcenter.rac.kernel.TCComponentUser;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.util.Registry;

public class BomAuthorizeOperation extends AbstractAIFOperation {

	  private final TCComponent childCmp;
	  private final TCComponentGroupMember grpMember;
	  
	  public BomAuthorizeOperation(AIFComponentContext paramAIFComponentContext, TCComponentGroupMember paramTCComponentGroupMember)
	  {
	    super(Registry.getRegistry(ChangeOwnershipOperation.class).getString("changeOwnershipObjects") + " " + paramAIFComponentContext.getComponent().toString());
	    this.childCmp = ((TCComponent)paramAIFComponentContext.getComponent());
	    this.grpMember = paramTCComponentGroupMember;
	  }
	  
	  public BomAuthorizeOperation(TCComponent component, TCComponentGroupMember paramTCComponentGroupMember)
	  {
	    super(Registry.getRegistry(ChangeOwnershipOperation.class).getString("changeOwnershipObjects") + " " + component.toString());
	    this.childCmp = component;
	    this.grpMember = paramTCComponentGroupMember;
	  }

	  public void executeOperation()
	    throws TCException
	  {
	    try
	    {
	      TCComponentUser localTCComponentUser = this.grpMember.getUser();
	      TCComponentGroup localTCComponentGroup = this.grpMember.getGroup();
	      this.childCmp.changeOwner(localTCComponentUser, localTCComponentGroup);
	      
	      if (this.childCmp instanceof TCComponentTask)
	      {
	        String str = ((TCComponentTask)this.childCmp).getTaskType();
	        if (str.equals("EPMPerformSignoffTask"))
	          this.childCmp.fireComponentChangeEvent();
	      }
	    }
	    catch (TCException localTCException)
	    {
	        throw localTCException;
	    }
	  }
  
}
